package com.dragon.refect.method;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author dragon
 * @since 2019/12/2
 */
public class MethodTest {

    public static void main(String[] args) throws Exception {
        Class<Book> bookClass = Book.class;
        Book bookInstance = bookClass.newInstance();
        Method[] methods = bookClass.getMethods();
        System.out.println(Arrays.toString(methods));
        System.out.println("=============================");
        Method[] declaredMethods = bookClass.getDeclaredMethods();
        System.out.println(Arrays.toString(declaredMethods));
        System.out.println("==============================");
        Method b = bookClass.getDeclaredMethod("b");
        Object invoke = b.invoke(bookInstance);
        System.out.println(invoke);
        System.out.println("=============================");
        Method b1 = bookClass.getDeclaredMethod("a", String.class, Integer.class);
        Class<?>[] parameterTypes = b1.getParameterTypes();
        System.out.println("parameterTypes: " + Arrays.toString(parameterTypes));
        int parameterCount = b1.getParameterCount();
        System.out.println("parameterCount:" + parameterCount);
        Class<?> returnType = b1.getReturnType();
        System.out.println("returnType: " + returnType);
    }
}
